<%--
  Created by IntelliJ IDEA.
  User: Li Chuanwei
  Date: 2023-07-17
  Time: 17:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>订单结算</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all">
    <script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/fontawesome/css/all.css" media="all">
    <style>
        body {
            background: rgb(234, 232, 235);
        }

        .mainContainer {
            margin-top: 5vh;
            margin-left: 11vw;
            width: 78vw;
            background: white;
            border: 1px solid #f2f2f2;
            border-radius: 10px;
            padding: 10px;
        }

        .centerContainer {
            margin-top: 1%;
            width: 100%;
        }

        .layui-card {
            border: 1px solid #f2f2f2;
            border-radius: 5px;
        }

        .icon {
            margin-right: 10px;
            color: #1aa094;
        }

        .layuimini-qiuck-module {
            text-align: center;
            margin-top: 10px
        }

        .layuimini-qiuck-module a i {
            display: inline-block;
            width: 100%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            border-radius: 2px;
            font-size: 30px;
            background-color: #F8F8F8;
            color: #333;
            transition: all .3s;
            -webkit-transition: all .3s;
        }

        .layuimini-qiuck-module a cite {
            position: relative;
            top: 2px;
            display: block;
            color: #666;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-size: 14px;
        }

        .main_btn > p {
            height: 40px;
        }

        .goodsCard {
            width: 100%;
            height: 160px;
            border-radius: 5px;
            background: rgb(247, 249, 250);
            position: relative;
        }

        .goodsCard img {
            padding: 5px;
            border-radius: 10px;
            max-width: 10vw;
            max-height: 10vw;
            min-width: 10vw;
            min-height: 10vw;
        }

        .goodsContainer {
            padding: 10px;
        }

        .goodsText {
        }

        .goodsInfo {
            margin-top: 10px;
            font-size: 1.1em;
        }

        .goodsPrice {
            color: red;
            font-size: 2em;
            margin-top: 50%;
        }

        .layui-table-cell {
            text-align: center;
            height: auto !important;
            white-space: normal;
        }

    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!-- 头部 -->
        <div class="layui-row">
            <jsp:include page="../common/_top.jsp"></jsp:include>
        </div>

        <div class="mainContainer">
            <div class="layui-row">
                <p style="font-size: 2em;margin-bottom: 20px;margin-top: 20px;font-family: 宋体;font-weight: bold;margin-left: 10px">
                    <i class="fa fa-clipboard-check" style="color: red;margin-right: 10px"></i>订单结算
                </p>
            </div>
            <div class="layui-row">
                <p style="font-size: 1.5em;margin-bottom: 20px;margin-top: 20px;font-family: 宋体;font-weight: bold;margin-left: 10px">
                    选择收获地址
                </p>

                <table class="layui-hide" id="addressTable" lay-filter="addressTable"></table>

                <script type="text/html" id="addressMap">
                    <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="mapView" style="margin: auto"><i class="fa fa-location-arrow"></i> 地址显示</a>
                </script>

            </div>

            <div class="layui-row">
                <p style="font-size: 1.5em;margin-bottom: 20px;margin-top: 20px;font-family: 宋体;font-weight: bold;margin-left: 10px">
                    订单详情（订单已生成，待支付）
                </p>
                <table class="layui-table" lay-skin="line">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>名字</th>
                        <th>图片</th>
                        <th>价格</th>
                        <th>数量</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${cartItemVOList}" var="cartItemVO" varStatus="status">
                        <tr>
                            <td>${status.index + 1}</td>
                            <td>${cartItemVO.name}</td>
                            <td><img src="${IMG_SERVER}/goods/${cartItemVO.pic}" onclick="showBigImage(this)"
                                     style="width: 100% ; height: 100%"
                                     class="goodsPic"></td>
                            <td>${cartItemVO.price2}</td>
                            <td>${cartItemVO.storage}</td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <p style="font-size: 2em;color: red;text-align: right">商品总价：${sum}元</p>
                <button class="layui-btn layui-btn-danger layui-btn-radius" id = "buyOrder" style="margin-left: 90%;margin-top: 10px" onclick="pay()">支付</button>
            </div>
        </div>
    </div>
</div>

</div>
<script>
    function pay(){
        window.location.href = "${pageContext.request.contextPath}/user/order/pay?orderNo=" + ${orderNo} ;
    }
</script>
<script>
    layui.use(['form', 'table', 'element', 'layer'], function (message) {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        dropdown = layui.dropdown;

        /**
         * 表格渲染
         */
        table.render({
            elem: '#addressTable',
            url: '${pageContext.request.contextPath}/manager/address/list',
            where:{
                userId:${sessionScope.user.getId()}
            },
            cols: [[
                {type: "radio"},
                {title: '序号', type: "numbers", align: "center"},
                {field: 'receiver', title: '收货人姓名'},
                {field: 'provinceName',  title: '所属省'},
                {field: 'cityName', title: '所属市'},
                {field: 'countryName', title: '所属区/县'},
                {field: 'addr',title: '具体地址'},
                { title: '地图查看',toolbar: "#addressMap"},
                {field: 'phone', title: '电话'},
            ]],
            loading: true,
            skin: 'line',
        });

        table.on('tool(addressTable)', function (obj) {
            var data = obj.data; // 获得当前行数据
            // 获取当前选中行的索引值

            // console.log(obj)
            if (obj.event === 'mapView') {
                var index = layer.open({
                    title: '',
                    type: 2,
                    shade: 0.2,
                    title: false, // 不显示标题栏
                    shadeClose: true,
                    offset: '20px',
                    area:['80%', '80%'],
                    content: '${pageContext.request.contextPath}/manager/address/map?address=' + data.provinceName + data.cityName + data.countryName + data.addr,
                });
            }
        });
    });
</script>
</body>
</html>
